//@note 头部地址填入
(function(w){$('.isea-h-location').html(w.getCity()||w.getLocalCity()||'未知') ;}(window)) ;

//@note 地址选择
(function(win){

    var location = need('location') ;
    $('.isea-h-location').on('click',function(){
        var self = $(this) ;
        location.open(function(list){
            if( list.length <= 0 ){ return ; }
            win.setCity(list[0].name) ;
            self.html(list[0].name) ;
        },{
            single : true 
        }) ;
    }) ;

}(window)) ;

//@note 公告信息滑动
(function(win){

    var screen = $('.w-switch') ;
    var box = need('console') ;

    //@note 可视的窗口
    screen.each(function(){
        var container  = $('.w-switch-cnt') ;
        var self = $(this) ;
        var width = 18;
        var count = container.find('.w-switch-item').length ;
        var long = 4.5 * count ;
        var goLeft = function( container , left ){
            var fix = ['','-moz-','-o-','-webkit-','-ms-'] ;
            for( var i = 0 ; i < fix.length ; i++ ){
                container.css(fix[i]+'transform','translate('+left+'rem,0)') ;
            }
        } ;
        var move = {
            _st : 0 ,
            left : function(){
                if( this._st - width > -long  ){
                    goLeft(container,this._st-=width) ;
                }
            } ,
            right : function(){
                if( this._st + width <= 0  ){
                    goLeft(container,this._st+=width) ;
                }
            }
        } ;
        var touchs = {
            _startPoint : null ,
            _endPoint : null ,
            start : function(point){
                this._startPoint = point.pageX ;
            } ,
            end : function(point){
                this._endPoint = point.pageX ;
            } ,
            isLeft : function(){
                if( this._endPoint && this._startPoint && ( this._startPoint - this._endPoint > 0 ) ){
                    return true ;
                } else {
                    return false ;
                }
            }
        } ;
        var point = ({
            _container : $('.w-point') ,
            _sel : 'w-point-itemSel' ,
            _cls : 'w-point-item' ,
            _cur : 0 ,
            _render : function(){
                this._container.find('.'+this._cls).removeClass(this._sel).eq(this._cur).addClass(this._sel) ; ;
            } ,
            left : function(){
                if( this._cur === this.max - 1 ){
                    return ;
                }
                this._cur ++ ;
                this._render() ;
            } ,
            right : function(){
                if( this._cur === 0 ){
                    return ;
                }
                this._cur -- ;
                this._render() ;
            } ,
            init : function(){
                this.max = Math.ceil(count/4) ;
                for( var i = 0 ; i < this.max ; i++ ){
                    this._container.append('<div class=" ' + this._cls + ' "></div>') ;
                }
                this._render();
                return this ;
            }
        }).init() ;
        self.on('touchstart',function(e){
            touchs.start(e.touches[0]) ;

        }) ;
        self.on('touchmove',function(e){
            touchs.end(e.touches[0]) ;

        }) ;
        self.on('touchend',function(e){
            if(touchs.isLeft()){
                move.left();
                point.left() ;
            }else{
                move.right();
                point.right() ;
            }

        });
    }) ;

}(window)) ;